package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.CpJydStatus;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;

import com.ruoyi.system.domain.quality.QualityProcessInspection;
import com.ruoyi.system.mapper.QualityProcessInspectionMapper;
import com.ruoyi.system.service.IQualityProcessInspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author GE-LV5
 * @create 2023/2/28 10:34
 * ==================过程检验单=============
 */
@Service
public class QualityProcessInspectionServiceImpl extends ServiceImpl<QualityProcessInspectionMapper, QualityProcessInspection> implements IQualityProcessInspectionService {
    @Autowired
    QualityProcessInspectionMapper qualityProcessInspectionMapper;

    /**
     * 添加过程检验单
     *
     * @param quality 过程检验单
     * @return
     */
    @Override
    @Transactional
    public int insertQualityProcessInspection(QualityProcessInspection quality) {
    /*    if(quality.getStatus().isEmpty()){
            throw new CustomException("状态不能为空！");
        }*/
        quality.setCreateTime(DateUtils.getNowDate());
        quality.setCreateBy(SecurityUtils.getUsername());
        quality.setUpdateBy(SecurityUtils.getUsername());
        quality.setUpdateTime(DateUtils.getNowDate());
        return qualityProcessInspectionMapper.insertQualityProcessInspection(quality);
    }

    /**
     * 查询过程检验单
     *
     * @param vo
     * @return
     */
    @Override
    public List<QualityProcessInspection> selectQualityProcessInspection(QualityProcessInspection vo) {
        return qualityProcessInspectionMapper.selectQualityProcessInspection(vo);
    }


    /**
     * 删除过程检验单
     *
     * @param id 过程检验单
     * @return
     */
    @Override
    public int deleteQualityProcessInspectionById(Long id) {
        if (CpJydStatus.INSPECTION_CENTER.equals("1")) {
            throw new CustomException("过程检验中不能删除！");
        }
        return qualityProcessInspectionMapper.deleteQualityProcessInspectionById(id);
    }




}
